package bigraph.part.tree;

import java.beans.PropertyChangeEvent;
import java.util.List;

import org.eclipse.gef.EditPolicy;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import bigraph.editpolicies.AppDeletePolicy;
import bigraph.editpolicies.AppRenamePolicy;
import bigraph.model.Node;
import bigraph.model.Root;

public class RootTreeEditPart extends AppAbstractTreeEditPart {

	protected List<Node> getModelChildren() {
	     return ((Root)getModel()).getChildrenArray();
	}
	
    @Override
    protected void createEditPolicies() {
         installEditPolicy(EditPolicy.COMPONENT_ROLE,new AppDeletePolicy());
         installEditPolicy(EditPolicy.NODE_ROLE, new AppRenamePolicy());
    }
    public void refreshVisuals(){
         Root model = (Root)getModel();
         setWidgetText(model.getName());
         setWidgetImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT));
    }

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
	     if(evt.getPropertyName().equals(Node.PROPERTY_ADD)) refreshChildren();
	     if(evt.getPropertyName().equals(Node.PROPERTY_REMOVE)) refreshChildren();
	     if (evt.getPropertyName().equals(Node.PROPERTY_RENAME)) refreshVisuals();
	}

}
